import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  // ...
  // optimizeDeps: {
  //   include: ['./src/views/**/*.vue'],
  // },
  plugins: [
    vue(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  
  server:{
    proxy:{
      '/api': {
        target: 'http://127.0.0.1:7777', // 将请求转发到这个地址
        changeOrigin: true,
        rewrite: (path:string) => path.replace(/^\/api/, '') ,// 根据实际情况进行路径重写
        bypass(req, res, options) {
          req.headers['X-Forwarded-For'] = req.socket.remoteAddress
          req.headers['X-Real-IP'] = req.socket.remoteAddress
        },
      },
      '/socket':{
        target:"http://127.0.0.1:7777",
        changeOrigin:true,
        ws: true
      }
    }
  }
})